package com.example.study.conf;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.google.common.base.Charsets;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.MediaType;

import java.util.Arrays;

/**
 * 文件上传配置
 */
@ComponentScan
public class WebConfig {





    @Bean
    public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
        FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
        fastJsonHttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
        fastJsonHttpMessageConverter.setDefaultCharset(Charsets.UTF_8);
        return fastJsonHttpMessageConverter;
    }

//    @Bean
//    public MultipartConfigElement multipartConfigElement(@Value("${multipart.maxFileSize}") Integer maxFileSize, @Value("${multipart.maxRequestSize}") Integer maxRequestSize) {
//        MultipartConfigFactory factory = new MultipartConfigFactory();
//        factory.setMaxFileSize(DataSize.of(maxFileSize, DataUnit.MEGABYTES));
//        factory.setMaxRequestSize(DataSize.of(maxRequestSize, DataUnit.MEGABYTES));
//        return factory.createMultipartConfig();
//    }
}